﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PSE.Tools.SchemaComparer.Extractor
{
    public static class StringExtension
    {
        public static long CountLines(this string text)
        {
            if (text == null)
                throw new ArgumentException("The parameter canot be null", "text");


            long count = 1;
            int start = 0;
            while ((start = text.IndexOf('\n', start)) != -1)
            {
                count++;
                start++;
            }
            return count;

        }

        public static int CountWordsOcurrence(this string text, string word)
        {
            int wordLenght = word.Length;
            int originalLenght = text.Length;
            string tempText = text.ToUpper().Replace(word.ToUpper(), "").Replace("\r\n", "  ").Replace("(", " ").Replace("\t", " ");

            return ((originalLenght - tempText.Length) / wordLenght);
        }
    }
}
